var fs = require('fs'),
	notif = require('../../core/notifications'),
	utils = require('../../core/module');

var config = new utils.ConfigModule('monitoring_temperature');

function execute(data, idModule) {

	// TODO modifier l'utilisation de 'data' selon ce qu'on envoie dans sources/enocean.js
	var temperature = data.value.toString();
	console.log('temperature -- ' + temperature);
	config.get(idModule, function (error, temperatureConfig) {

		if (!error) {
			
			var temperatureMax = parseFloat(temperatureConfig.max_temperature);
			
			if (temperature > temperatureMax) {
				console.log('Temperature max atteinte. Envoie d\'une notif push !');
				var payload = {
					"threshold": temperatureConfig.max_temperature,
					"current": temperature,
					"date": new Date().toString()
				}
				notif.notify('temperature', JSON.stringify(payload));
			}
		} else {
			console.log(error);
		}

	});

}

module.exports.execute = execute;

